package com.thinksmart.qfilemanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.thinksmart.qfilemanager.R;
import com.thinksmart.qfilemanager.widget.listItem;

import java.util.List;

/**
 * Created by F3060803 on 2017/6/20.
 */

public class FilelistItemAdapter extends BaseAdapter {
    private List<listItem> mData = null;
    private Context mContext = null;

    public FilelistItemAdapter(List<listItem> data, Context context) {
        mData = data;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData == null ? 0 : mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View view = layoutInflater.inflate(R.layout.list_item, null);

        listItem item = (listItem) mData.get(position);
        ImageView imageView = (ImageView) view.findViewById(R.id.img_Icon);
        TextView textView = (TextView) view.findViewById(R.id.tv_fileName);
        CheckBox checkBox = (CheckBox) view.findViewById(R.id.chk_Select);

        if (item != null) {
            imageView.setImageResource(item.getIcon());
            textView.setText(item.getText());
            checkBox.setSelected(item.isItemChecked());
        }

        return view;
    }
}
